package com.itheima.controller;

import com.itheima.pojos.Student;
import com.itheima.utils.MinIo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author wangjiexin
 */
//不能用@RestController只能用@Controller 因为返回的是一个页面而不是一个字符串
@Controller
public class TestController {

    @PostMapping("upload")
    public String upload(MultipartFile file) throws IOException {
        //接收图片内容

        //调用minIO工具
      MinIo minIo=new MinIo();
        String url = minIo.uploadFile("", "测试图片", file.getInputStream(), "png");
        //测试图片远程路径是否可以访问
        System.out.println(url);

        return url;
    }

    @GetMapping("/basic")
    public String test(Model model) {
        //1.纯文本形式的参数
        model.addAttribute("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        model.addAttribute("stu", student);

        return "01-basic";
    }
}
